home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / tpl60n19.zip / ARISOURC.ZIP / FP48FLT.ASM < prev    next >
Assembly Source File  |  1993-01-24  |  3KB  |  80 lines

  1.  
  2. ; *******************************************************
  3. ; *                                                     *
  4. ; *     Turbo Pascal Runtime Library Version 6.0        *
  5. ; *     Real Longint -> Real Conversion                 *
  6. ; *                                                     *
  7. ; *     Copyright (C) 1989-1992 Norbert Juffa           *
  8. ; *                                                     *
  9. ; *******************************************************
  10.  
  11.              TITLE   FP48FLT
  12.  
  13.              INCLUDE SE.ASM
  14.  
  15.  
  16. CODE         SEGMENT BYTE PUBLIC
  17.  
  18.              ASSUME  CS:CODE
  19.  
  20. ; Publics
  21.  
  22.              PUBLIC  RealFloat,RFloat
  23.  
  24. ;-------------------------------------------------------------------------------
  25. ; RealFloat converts a four byte signed long integer number to the six byte
  26. ; TURBO-Pascal floating point format.
  27. ;
  28. ; INPUT:     DX:AX      longint number
  29. ;
  30. ; OUTPUT:    DX:BX:AX   real number
  31. ;
  32. ; DESTROYS:  AX,BX,CH,DX,Flags
  33. ;-------------------------------------------------------------------------------
  34.  
  35. RealFloat    PROC    NEAR
  36.              MOV     BX, AX            ; save low word of longint
  37.              OR      AX, DX            ; is longint = 0 ?
  38.              JZ      $real_zero        ; yes, result is real zero
  39.              MOV     CH, 7Fh           ; load mask for sign bit
  40.              OR      CH, DH            ; extract sign bit (clear carry flag)
  41.              JNS     $long_pos         ; no sign bit, number is positive
  42.              NEG     DX                ; negate
  43.              NEG     BX                ;  long integer
  44. $long_pos:   SBB     DX, 0             ;   in DX:BX
  45.              MOV     AX, 0A0h          ; set exponent (assume all bits set)
  46.              JNZ     $hiword_set       ; high word of longint not zero
  47.              XCHG    DX, BX            ; do a 16-bit left shift on DX:BX
  48.              MOV     AL, 90h           ; assume last 24 bits in longint set
  49. $hiword_set: OR      DH, DH            ; test, wether more than 16 bits set
  50.              JNZ     $hibyte_set       ; yes, exponent correct
  51.              SUB     AL, 8             ; adjust exponent
  52.              OR      DH, DL            ; do an
  53.              MOV     DL, BH            ;  eight bit
  54.              MOV     BH, BL            ;   left shift
  55.              MOV     BL, AH            ;    on DX:BX
  56. $hibyte_set: JS      $normalized       ; yes, mantissa ready
  57.  
  58.              ALIGN   4
  59.  
  60. $shift_bit:  DEC     AX                ; adjust exp. for left shift of mantissa
  61.              ADD     BX, BX            ; shift mantissa one
  62.              ADC     DX, DX            ;  bit to the left
  63.              JNS     $shift_bit        ; until msb of mantissa set
  64. $normalized: AND     DH, CH            ; mask out sign bit if necessary
  65. $real_zero:  RET                       ; done
  66. RealFloat    ENDP
  67.  
  68.              ALIGN   4
  69.  
  70. RFloat       PROC    FAR
  71.              CALL    RealFloat         ; perform conversion longint to real
  72.              RET                       ; done
  73. RFloat       ENDP
  74.  
  75.              ALIGN   4
  76.  
  77. CODE         ENDS
  78.  
  79.              END
  80.